package vip.bblog.cunadmin.modules.system.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import vip.bblog.cunadmin.common.entity.PageResult;
import vip.bblog.cunadmin.modules.system.dto.SysLogParams;

import vip.bblog.cunadmin.modules.system.entity.SysLog;
import vip.bblog.cunadmin.modules.system.mapper.SysLogMapper;
import vip.bblog.cunadmin.modules.system.service.SysLogService;

import java.util.List;

/**
 * <p>
 * c操作日志
 * </p>
 *
 * @author yy
 * @since
 */
@Service
public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> implements SysLogService {

    @Override
    public PageResult<List<SysLog>> listPage(SysLogParams params) {
        Page<SysLog> page = params.getIPage();
        LambdaQueryWrapper<SysLog> queryWrapper = Wrappers.lambdaQuery();
        //根据操作内容名查询
        if (StringUtils.isNotBlank(params.getContent())) {
            queryWrapper.like(SysLog::getContent, params.getContent());
        }
        //根据操作描述查询
        if (StringUtils.isNotBlank(params.getContent())) {
            queryWrapper.like(SysLog::getDescription, params.getDescription());
        }
        //根据操作类型查询
        if (params.getHandleType() != null) {
            queryWrapper.eq(SysLog::getHandleType, params.getHandleType());
        }
        queryWrapper.orderByDesc(SysLog::getCtime);
        Page<SysLog> pageResult = this.page(page, queryWrapper);
        List<SysLog> list = pageResult.getRecords();

        return PageResult.success(list, pageResult.getTotal());
    }

}
